using System;
using System.Reflection;
using System.Collections.Generic;



namespace Open.Data.Persistence.SqlServer
{ 
    //Follows the singleton design pattern
	public class SqlProvider: IProvider 
	{
		//Singleton instance
		public static readonly SqlProvider Instance = new SqlProvider();

		//Property variables
        private static ReflectionCache _reflectionCache;
        
		//Constructors
		private SqlProvider()
		{
            _reflectionCache = new ReflectionCache(this);
		}

        //Properties
    	public ReflectionCache ReflectionCache
		{
			get
			{
				return _reflectionCache;
			}
		}

        //Methods
        public ReflectionParser CreateParser()
        {
            return new SqlReflectionParser();
        }

        public CacheItem CreateCacheEntry(Type type, ReflectionParser parser)
        {
            if (!(parser is SqlReflectionParser)) throw new ArgumentException(string.Format("Parser is not of type {0}.", typeof(SqlReflectionParser).Name));
            return new SqlCacheItem(type, parser as SqlReflectionParser);
        }
	}
}
